import { createRouter, createWebHistory } from 'vue-router'
import { useLoginEmpStore } from '@/stores/loginEmp'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [ //配置路由信息
        {
          path:'/',
          name:'home',
          component:()=>import('@/views/front/layout.vue'),
          // redirect:'/index',
          children:[
            {
              path:'front_index',
              name:'front_index',
              component:()=>import('@/views/front/index.vue'),
            },
            {
              path:'front_armors',
              name:'front_armors',
              component:()=>import('@/views/front/armors.vue'),
            },
            {
              path:'front_firearms',
              name:'front_firearms',
              component:()=>import('@/views/front/firearms.vue'),
            },
            {
              path:'front_materials',
              name:'front_materials',
              component:()=>import('@/views/front/materials.vue'),
            },
            {
              path:'front_roomCard',
              name:'front_roomCard',
              component:()=>import('@/views/front/roomCard.vue'),
            },
            {
              path:'front_expansionBox',
              name:'front_expansionBox',
              component:()=>import('@/views/front/expansionBox.vue'),
            },
            {
              path:'front_tqc',
              name:'front_tqc',
              component:()=>import('@/views/front/tqc.vue'),
            },
          ]
        },

        {
          path:'/manager',
          name:'manager',
          component:()=>import('@/views/manager/layout.vue'),
          children:[
            {
              path:'index',
              name:'index',
              component:()=>import('@/views/manager/index.vue'),
            },
            {
              path:'armors',
              name:'armors',
              component:()=>import('@/views/manager/armors.vue'),
            },
            {
              path:'firearms',
              name:'firearms',
              component:()=>import('@/views/manager/firearms.vue'),
            },
            {
              path:'materials',
              name:'materials',
              component:()=>import('@/views/manager/materials.vue'),
            },
            {
              path:'roomCard',
              name:'roomCard',
              component:()=>import('@/views/manager/roomCard.vue'),
            },
            {
              path:'expansionBox',
              name:'expansionBox',
              component:()=>import('@/views/manager/expansionBox.vue'),
            },
            {
              path:'tqc',
              name:'tqc',
              component:()=>import('@/views/manager/tqc.vue'),
            },
          ]
        },
        {
          path:'/login',
          name:'login',
          component:()=>import('@/views/login/login.vue'),
        },
      ]
    },
    
   
  
)


// 全局前置守卫
// router.beforeEach((to, from, next) => {
//   const loginEmpStore = useLoginEmpStore();
//   const isLoggedIn = loginEmpStore.getLoginEmp()?.token; // 检查是否有 token

//   // 需要登录的路径：以 /manager 开头的路径
//   const requiresAuth = to.path.startsWith('/manager');

//   if (requiresAuth && !isLoggedIn) {
//     next('/login'); // 未登录则重定向到登录页
//   } else {
//     next(); // 放行请求
//   }
// });


export default router
